import React from 'react';

import styles from './picturebox.css';
import getThemeColor from "../../utils/themeutil";

class PictureBox extends React.Component {

  componentDidMount() {
    this.props.toTop && this.node.scrollIntoView();
  }

  render() {
    const {src, item} = this.props;

    const clz = item ? styles["item-pic-box"] : "";
    return (
      <span ref={node => this.node = node}>
      {
        src ?
          <img src={src} alt={'图'} className={styles["pic-box"] + ' ' + clz}/>
          :
          <div className={styles["color-box"] + ' ' + clz}
               style={{
                 backgroundColor: getThemeColor()
               }}>
            <span>{this.props.text}</span>
          </div>
      }
      </span>
    );
  }

}

export default PictureBox;
